package gui;

import java.util.ArrayList;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.graphics.GC;


public class PackageShape extends Shape{
	
	private int x,y,height,width;
	private String packageName;
	private ArrayList<PackageShape> children = new ArrayList<PackageShape>();
	private Rectangle bodyRectangle , nameRectangle ;
	
	
	public void setName(String _packageName)
	{
		packageName = _packageName ;		
	}
	
	public void setPoint(int _x,int _y)
	{
		x= _x;
		y= _y;
		
	}
	
	public void setHeightWidth(int _height, int _width)
	{
		height = _height;
		width = _width;
		
	}
	
	public void addChild(PackageShape child) {
		
		children.add(child);
		
	}
	
	public int getHeight()
	{
		return height;		
	}
	
	public int getWidth()
	{
		return width;		
	}
	
	public ArrayList<PackageShape> getChildren()
	{
		return children;		
	}
	
	
	@Override
	public void DrawShape(Canvas canvas) {
		// TODO Auto-generated method stub
		
		GC gc = new GC(canvas);
		
		Point name = gc.stringExtent(packageName) ;
		
		
		if(children.size()==0)
		{	
			nameRectangle = new Rectangle(x, y , width / 3  ,  10 );
			nameRectangle.DrawShape(canvas);
			
			bodyRectangle = new Rectangle(x, y + 10 , width , 50 );
			bodyRectangle.DrawShape(canvas);
			
			gc.drawString(packageName, (x + 8), (y + 4) );
		}
		
		else 
		{			
			nameRectangle = new Rectangle(x, y , 16 + name.x  ,  8 + name.y );
			nameRectangle.DrawShape(canvas);
			
			bodyRectangle = new Rectangle(x, y + nameRectangle.getHeight() , width, height - nameRectangle.getHeight() );
			bodyRectangle.DrawShape(canvas);
			
			gc.drawString(packageName, (x + 8), (y + 4) );
			
		}	
	}

}
